package com.android.lmy;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.android.lmy.SqlLiteDemo.DatabaseHelper;
import com.android.lmy.SqlLiteDemo.Student;
import com.android.lmy.SqlLiteDemo.StudentDao;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button button2;
    private Button button3;
    private Button button4;
    private Button button5;
    private TextView showtext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button2 = findViewById(R.id.button2);
        button3 = findViewById(R.id.button3);
        button4 = findViewById(R.id.button4);
        button5 = findViewById(R.id.button5);
        showtext = findViewById(R.id.showtext);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);
        button5.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button2:
//                for (int i = 0; i < 20; i++) {
//                    StudentDao.getInstance(this).addstudent(new Student("李明洋",  UUIDUtils.getUUID(6), "男", 999));
//
//                }
                ContentValues contentValues1s = new ContentValues();
                contentValues1s.put("name", "小明");
                contentValues1s.put("sex", "女");
                contentValues1s.put("age", 19);
                contentValues1s.put("studentid", UUIDUtils.getUUID(6));
                StudentDao.getInstance(this).addstudentCursor(contentValues1s);
                break;
            case R.id.button3:
                StudentDao.getInstance(this).deletestudent("studentid = ?", new String[0]);
                break;
            case R.id.button4:
                ContentValues contentValues = new ContentValues();
                contentValues.put("name", "小明A");
                contentValues.put("sex", "女A");
                contentValues.put("age", 111);
                StudentDao.getInstance(this).updatestudent(contentValues, "0");
                break;
            case R.id.button5:
                if (StudentDao.getInstance(this).getstudentlist() != null) {
                    Student student = StudentDao.getInstance(this).getstudentlist().get(0);
                    showtext.setText(student.getName() + student.getStudentid() + student.getSex() + student.getAge());
                    Log.e("TTT", StudentDao.getInstance(this).getstudentlist().size() + StudentDao.getInstance(this).getstudentlist().toString());
                } else {
                    Toast.makeText(this, "暂无数据", Toast.LENGTH_SHORT).show();
                }

                break;
        }
    }
}
